Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Supplier orders : delete dispatched lines on supplier order deletion #25292

Merged
merged 11 commits into from
Nov 12, 2024

Conversation

ibuiv
Copy link
Contributor

@ibuiv ibuiv commented Jul 6, 2023

FIX|Fix #[Supplier orders : delete dispatched lines on supplier order deletion]

If stock increase is set up to dispatch to warehouse manually, the order deletion may cause stock issues.
You can valid an order, dispatch some lines (increasing your stock) and delete the order.
The lines are dispatched, the stock moves are written and you cannot access to the dispatch lines because the order has been removed from the database.
A warning has been added on deletion modal if there are existing dispatched lines.
If confirmed, for each dispatched line, we apply the same method used by clicking on the trash icon on a dispatch line.
The label for the stock move generated will be trans('SupplierOrderDeletion') By default : Supplier order %s Deletion

@eldy
Copy link
Member

eldy commented Jul 7, 2023

When product were shipped, and order is canceled after, the product are still shipped.
For this reason, an order deletion should not affect the stock. A deletion is an action to "clean database", not a business event. For a business event, the action "cancel" is better. There is a lot of use cas also we need to delete and without reverting stock change already done.
So adding a warning that there is some stock movement already recorded, during order deletion, is a very good thing. But the message must also say:

  1. solution 1: explain that if a stock movement must be reverted, this must be done manually because not done by default
  2. Solution 2: explain that if a stock movement were already recorded, and ask the user if this must be reverted or not (end user must decide).

@eldy eldy added the Discussion Some questions or discussions are opened and wait answers of author or other people to be processed label Jul 7, 2023
@ibuiv
Copy link
Contributor Author

ibuiv commented Aug 31, 2023

@eldy
Ok solution 2 was applied
image

Text is added to en_US trans only

@ibuiv ibuiv requested a review from eldy August 31, 2023 09:53
$dispatchedLines = $object->getDispachedLines();
if (!empty($dispatchedLines)) {
foreach ($dispatchedLines as $dispatchedLine) {
$db->begin();
Copy link
Member

@eldy eldy Sep 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The begin end transaction must not be inside the loop. We must have 1 transaction for all the event so result in database will be everything done or nothing.
Commit must be after the delete if order

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified code to locate correctly begin, rollback and commit instructions for db.
I noticed that $commande->delete also have a begin, rollback and commit logic on $this->db in the commande.class.php file.
If two transactions have begun in parallel, I prefered to finish all the logic on $db in the card.php code.

@eldy eldy added PR to fix - See feedback in comments PR needs to be fixed to be integrated (some comments should describes the fix to do) and removed Discussion Some questions or discussions are opened and wait answers of author or other people to be processed labels Sep 2, 2023
@ibuiv ibuiv requested a review from eldy September 12, 2023 15:47
@eldy eldy merged commit 369fb8b into Dolibarr:develop Nov 12, 2024
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR to fix - See feedback in comments PR needs to be fixed to be integrated (some comments should describes the fix to do)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants